﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;

namespace Succell.Dnn.JQuery.UI
{
    /// <summary>
    /// A collection of <see cref="TabPane"/>s used by the <see cref="Tabs"/> web control.
    /// </summary>
    public class TabPaneCollection : ViewCollection, IEnumerable<TabPane>
    {
        #region properties

        /// <summary>
        /// Gets the <see cref="TabPane"/> from the specified <paramref name="index"/>.
        /// </summary>
        /// <param name="index">The index of the <see cref="TabPane"/>.</param>
        /// <returns>The <see cref="TabPane"/> from the specified <paramref name="index"/>.</returns>
        public new TabPane this[int index]
        {
            get
            {
                return (TabPane)base[index];
            }
        }

        #endregion

        #region constructors

        /// <summary>
        /// Creates a new <see cref="TabPaneCollection"/> for the owning control.
        /// </summary>
        /// <param name="owner">The control owning the <see cref="TabPaneCollection"/>.</param>
        public TabPaneCollection(Control owner)
            : base(owner)
        {
        }

        #endregion

        #region methods

        /// <summary>
        /// Adds a <see cref="TabPane"/> to the collection.
        /// </summary>
        /// <param name="child">The <see cref="TabPane"/> to add.</param>
        public override void Add(Control child)
        {
            if (!(child is TabPane))
                throw new ArgumentException("Control is not of required type TabPane.", "child");

            base.Add(child);
        }

        /// <summary>
        /// Adds a <see cref="TabPane"/> to the collection.
        /// </summary>
        /// <param name="child">The <see cref="TabPane"/> to add.</param>
        public void Add(TabPane child)
        {
            base.Add(child);
        }

        /// <summary>
        /// Adds a <see cref="TabPane"/> to the collection at the specified <paramref name="index"/>.
        /// </summary>
        /// <param name="index">The index to add the <see cref="TabPane"/> at.</param>
        /// <param name="child">The <see cref="TabPane"/> to add to the collection.</param>
        public override void AddAt(int index, Control child)
        {
            if (!(child is TabPane))
                throw new ArgumentException("Control is not of required type TabPane.", "child");

            base.AddAt(index, child);
        }

        /// <summary>
        /// Adds a <see cref="TabPane"/> to the collection at the specified <paramref name="index"/>.
        /// </summary>
        /// <param name="index">The index to add the <see cref="TabPane"/> at.</param>
        /// <param name="child">The <see cref="TabPane"/> to add to the collection.</param>
        public void AddAt(int index, TabPane child)
        {
            base.AddAt(index, child);
        }

        /// <summary>
        /// Gets an enumerator for the <see cref="TabPaneCollection"/>.
        /// </summary>
        /// <returns>An enumerator for the <see cref="TabPaneCollection"/>.</returns>
        public new IEnumerator<TabPane> GetEnumerator()
        {
            foreach (TabPane tabPane in this)
            {
                yield return tabPane;
            }
        }

        #endregion
    }
}
